
const getTime = (time) => {
    //time = 7下周  -7上周   0本周
    let date = new Date(); //this.chaoZuoTime
    let currentFirstDate = new Date(date);

    let formatDate = function (date) {
        // console.log(date);
        let year = date.getFullYear(); //年
        let month = (date.getMonth() + 1).toString().padStart(2, '0'); //月
        let day = date.getDate().toString().padStart(2, '0'); //日;
        // let arr = ["日", "一", "二", "三", "四", "五", "六"];
        let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][
            date.getDay()
        ];
        let newday =
        {
            dateTime: year + '-' + month + '-' + day + ' ' + week,
            date: year + '-' + month + '-' + day,
            week: week
        }

        //我需要的格式是  （周几 月.日） 这里看你们的需求
        return newday;
    };

    let addDate = function (date, n) {
        // console.log(date.getDate() + n);
        date.setDate(date.getDate() + n);
        return date;
    };

    let setDate = function (date) {
        let week = date.getDay() - 1;//控制 日开头还是一开头
        date = addDate(date, week * -1);
        currentFirstDate = new Date(date);
        let weekList = [];
        for (let i = 0; i < 7; i++) {
            weekList[i] = formatDate(i == 0 ? date : addDate(date, 1));
        }
        return weekList;
    };


    let thisWeek = setDate(addDate(currentFirstDate, time)); //本周

    return thisWeek
}

export { getTime }

